//
//  VideoListItemView.swift
//  TestConcurreces
//
//  Created by rolodestar on 2025/6/16.
//

import SwiftUI
import BilibiliSearch
import Kingfisher

struct BiliVideoListItemView: View {
    var video: BilibiliNetVideo
    var body: some View {
        HStack(alignment: .top){
            KFImage(video.cover)
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: 60,height: 60)
                .clipShape(RoundedRectangle(cornerRadius: 7))
                .shadow(color: .gray, radius: 3, x: 0, y: 2)
            VStack(alignment:.leading) {
                Text("\(video.title)")
                    .font(.body)
                    .lineLimit(2)
                    .foregroundColor(.black)
                    .padding(.bottom, 2)
                Text("@\(video.author)  |  \(video.duration)")
                    .font(.footnote)
                    .foregroundColor(.black)
                    .padding(.bottom, 2)
                Text("#\(video.searchKeyword ?? "未分类")  |  播放次数：\(video.playCount)")
                    .font(.footnote)
                    .foregroundColor(.black)
                Spacer()
            }
            .padding(.leading, 10)
            Spacer()
        }
        .frame(maxHeight: 100)
        .padding(8)
        .background(video.localUrl == nil ? Color.gray.opacity(0.2) : Color.green.opacity(0.2)) // 根据本地存在情况设置背景色
        .cornerRadius(10)
        .shadow(color: .gray.opacity(0.3), radius: 5, x: 0, y: 2)
        .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading) // 确保背景框宽度一致
        .fixedSize(horizontal: false, vertical: true)
    }
}

#Preview {
    BiliVideoListItemView(video: BilibiliNetVideo.createModel(from: BilibiliSearchItemParsingResult.debguResult))
}
